<?xml version="1.0" encoding="UTF-8" ?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>	

<xsl:template match="/">	
	
<!--/////////// GENERATED CODE FOR VISUAL 2003 ///////////////-->
Imports System
Imports System.Reflection
Imports System.Collections
Imports USS = Evaluant.Uss
Imports Evaluant.Uss.ObjectContext		

'///////////// Code for Visual 2003 VB/////////////////////

	<xsl:apply-templates/>
	
</xsl:template>


<xsl:template match="Package">

Namespace <xsl:value-of select="@name"/>


<!--///////////////ENUMERATION DECLARATION ////////////////-->
	#Region "enumerations"
	<xsl:apply-templates select="Enumeration" mode="enum"/>
	#End Region

	<xsl:apply-templates>
		<xsl:with-param name="namespace" select="@name"/>
	</xsl:apply-templates>
<xsl:text> End Namespace </xsl:text>
</xsl:template>	

<!--///////////////ENUMERATION DECLARATION (Suite) ////////////////-->
<xsl:template match="Enumeration" mode="enum">
	Public Enum<![CDATA[ ]]><xsl:value-of select="@name"/><![CDATA[ ]]>
	<xsl:apply-templates select="Literal" mode="enum"/>
	End Enum
</xsl:template>

<xsl:template match="Literal" mode="enum">
	<xsl:value-of select="@name"/> <![CDATA[	]]>
</xsl:template>

<!--///////////////INTERFACE DECLARATION///////////////////-->


<xsl:template match="Interface">

	#Region "Interfaces"

	Public Interface <xsl:value-of select="@name"/>
	
	<xsl:apply-templates select="Property" mode="Interface">
	</xsl:apply-templates>	
	
	End Interface
	
	#End Region
</xsl:template>


<xsl:template match="Property" mode="Interface">

		Property <![CDATA[ ]]><xsl:value-of select="@name"/> As<![CDATA[ ]]><xsl:value-of select="@type"/>
</xsl:template>

<!--/////////////// MODELE METIER ///////////////////////////-->

<xsl:template match="Class">
<xsl:param name="namespace"/>


	#Region "<xsl:value-of select="@name"/>Collection"

	'/// &lt;summary&gt;
	'///     &lt;para&gt;
	'///       A collection that stores &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; objects.
	'///    &lt;/para&gt;
	'/// &lt;/summary&gt;
	'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection'/&gt;
	&lt;Serializable()&gt; _
	Public Class  <xsl:value-of select="@name"/>Collection 
		Inherits IPersistableCollection 
		
		'/// &lt;summary&gt;
		'///     &lt;para&gt;
		'///       Initializes a new instance of &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt;.
		'///    &lt;/para&gt;
		'/// &lt;/summary&gt;
		Public Sub New()
			
			MyBase.New
			
		End Sub
		
		'/// &lt;summary&gt;
		'///     &lt;para&gt;
		'///       Initializes a new instance of &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; based on another &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt;.
		'///    &lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;
		'///       A &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; from which the contents are copied
		'/// &lt;/param&gt;
		Public Sub New(ByVal val As <xsl:value-of select="@name"/>Collection)
			
			MyBase.New
			Me.AddRange(val)
		
		End Sub
		
		'/// &lt;summary&gt;
		'///     &lt;para&gt;
		'///       Initializes a new instance of &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; containing any array of &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; objects.
		'///    &lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;
		'///       A array of &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; objects with which to intialize the collection
		'/// &lt;/param&gt;
		Public Sub New(ByVal val() As <xsl:value-of select="@name"/>)
		
			MyBase.New
			Me.AddRange(val)
		
		End Sub
		
		Public Sub New(ByVal parentEntity As Uss.Entity ,ByVal role As String,ByVal data() As object)
		
			MyBase.New(parentEntity, role, data)
			'MyBase.New
			'_ParentEntity = parentEntity
			'_Role = role 
			
			'For Each o As object In data
			
            '   List.Add(o)
                
            'Next
			
			
		End Sub
		
		'/// &lt;summary&gt;
		'/// &lt;para&gt;Represents the entry at the specified  of the &lt;see cref='.<xsl:value-of select="@name"/>'/&gt;.&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name=''&gt;&lt;para&gt;The zero-based  of the entry to locate in the collection.&lt;/para&gt;&lt;/param&gt;
		'/// &lt;value&gt;
		'///    &lt;para&gt; The entry at the specified  of the collection.&lt;/para&gt;
		'/// &lt;/value&gt;
		'/// &lt;exception cref='System.ArgumentOutOfRangeException'&gt;&lt;paramref name=''/&gt; is outside the valid range of es for the collection.&lt;/exception&gt;
		Default Public Shadows Property  <xsl:value-of select="@name"/> (ByVal index As Integer) As <xsl:value-of select="@name"/>
		
			Get 
			
				Return CType(Me.List(index),<xsl:value-of select="@name"/>)
				
			End Get
			
			Set(ByVal value As <xsl:value-of select="@name"/>)
			
				Me.List(index) = value
				
			End Set
			
		End Property

            		
		'/// &lt;summary&gt;
		'///    &lt;para&gt;Adds a &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; with the specified value to the 
		'///    &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; .&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;The &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; to add.&lt;/param&gt;
		'/// &lt;returns&gt;
		'///    &lt;para&gt;The index at which the new element was inserted.&lt;/para&gt;
		'/// &lt;/returns&gt;
		'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection.AddRange'/&gt;
		Public Overloads Function Add(ByVal val As <xsl:value-of select="@name"/>) As Integer
		
			Return MyBase.Add(val)
		
		End Function
		
		'/// &lt;summary&gt;
		'///     &lt;para&gt;
		'///       Adds the contents of another &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; to the end of the collection.
		'///    &lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;
		'///    A &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; containing the objects to add to the collection.
		'/// &lt;/param&gt;
		'/// &lt;returns&gt;
		'///   &lt;para&gt;None.&lt;/para&gt;
		'/// &lt;/returns&gt;
		'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection.Add'/&gt;
		Public Overloads Sub AddRange(ByVal val As <xsl:value-of select="@name"/>Collection)
		
			MyBase.AddRange(val)
			
		End Sub
		
		Public Overloads Sub AddRange(ByVal val() As <xsl:value-of select="@name"/>)
		
			MyBase.AddRange(val)
			
		End Sub
		
		'/// &lt;summary&gt;
		'/// &lt;para&gt;Gets a value indicating whether the 
		'///    &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; contains the specified &lt;see cref='.<xsl:value-of select="@name"/>'/&gt;.&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;The &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; to locate.&lt;/param&gt;
		'/// &lt;returns&gt;
		'/// &lt;para&gt;&lt;see langword='true'/&gt; if the &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; is contained in the collection; 
		'///   otherwise, &lt;see langword='false'/&gt;.&lt;/para&gt;
		'/// &lt;/returns&gt;
		'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection.IndexOf'/&gt;
		Public Overloads Function Contains(ByVal val As <xsl:value-of select="@name"/>) As Boolean
		
			Return List.Contains(val)
			
		End Function
		
		'/// &lt;summary&gt;
		'/// &lt;para&gt;Copies the &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; values to a one-dimensional &lt;see cref='System.Array'/&gt; instance at the 
		'///    specified index.&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='array'&gt;&lt;para&gt;The one-dimensional &lt;see cref='System.Array'/&gt; that is the destination of the values copied from &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; .&lt;/para&gt;&lt;/param&gt;
		'/// &lt;param name='index'&gt;The index in &lt;paramref name='array'/&gt; where copying begins.&lt;/param&gt;
		'/// &lt;returns&gt;
		'///   &lt;para&gt;None.&lt;/para&gt;
		'/// &lt;/returns&gt;
		'/// &lt;exception cref='System.ArgumentException'&gt;&lt;para&gt;&lt;paramref name='array'/&gt; is multidimensional.&lt;/para&gt; &lt;para&gt;-or-&lt;/para&gt; &lt;para&gt;The number of elements in the &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; is greater than the available space between &lt;paramref name='arrayIndex'/&gt; and the end of &lt;paramref name='array'/&gt;.&lt;/para&gt;&lt;/exception&gt;
		'/// &lt;exception cref='System.ArgumentNullException'&gt;&lt;paramref name='array'/&gt; is &lt;see langword='null'/&gt;. &lt;/exception&gt;
		'/// &lt;exception cref='System.ArgumentOutOfRangeException'&gt;&lt;paramref name='arrayIndex'/&gt; is less than &lt;paramref name='array'/&gt;'s lowbound. &lt;/exception&gt;
		'/// &lt;seealso cref='System.Array'/&gt;
		Public Overloads Sub CopyTo(ByVal array() As <xsl:value-of select="@name"/>, index As Integer)
		
			List.CopyTo(array, index)
			
		End Sub
		
		'/// &lt;summary&gt;
		'///    &lt;para&gt;Returns the index of a &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; in 
		'///       the &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; .&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;The &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; to locate.&lt;/param&gt;
		'/// &lt;returns&gt;
		'/// &lt;para&gt;The index of the &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; of &lt;paramref name='value'/&gt; in the 
		'/// &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt;, if found; otherwise, -1.&lt;/para&gt;
		'/// &lt;/returns&gt;
		'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection.Contains'/&gt;
		Public Overloads Function IndexOf(ByVal val As <xsl:value-of select="@name"/>) As Integer
		
			Return List.IndexOf(val)

		End Function
		
		'/// &lt;summary&gt;
		'/// &lt;para&gt;Inserts a &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; into the &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; at the specified .&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name=''&gt;The zero-based  where &lt;paramref name='value'/&gt; should be inserted.&lt;/param&gt;
		'/// &lt;param name=' value'&gt;The &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; to insert.&lt;/param&gt;
		'/// &lt;returns&gt;&lt;para&gt;None.&lt;/para&gt;&lt;/returns&gt;
		'/// &lt;seealso cref='.<xsl:value-of select="@name"/>Collection.Add'/&gt;
		Public Overloads Sub Insert(ByVal index As Integer, val As <xsl:value-of select="@name"/>)
		
			List.Insert(index, val)
			
		End Sub
		
		'/// &lt;summary&gt;
		'///    &lt;para&gt; Removes a specific &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; from the 
		'///    &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; .&lt;/para&gt;
		'/// &lt;/summary&gt;
		'/// &lt;param name='value'&gt;The &lt;see cref='.<xsl:value-of select="@name"/>'/&gt; to remove from the &lt;see cref='.<xsl:value-of select="@name"/>Collection'/&gt; .&lt;/param&gt;
		'/// &lt;returns&gt;&lt;para&gt;None.&lt;/para&gt;&lt;/returns&gt;
		'/// &lt;exception cref='System.ArgumentException'&gt;&lt;paramref name='value'/&gt; is not found in the Collection. &lt;/exception&gt;
		Public Overloads Sub Remove(ByVal val As <xsl:value-of select="@name"/>)
		
			List.Remove(val)
		End Sub
		
		Public Class  <xsl:value-of select="@name"/>Enumerator
			Implements IEnumerator
		
			Dim baseEnumerator As IEnumerator
			Dim temp As IEnumerable
			
			Public Sub New(ByVal mappings As <xsl:value-of select="@name"/>Collection)

				Me.temp = DirectCast(mappings, IEnumerable)
				Me.baseEnumerator = temp.GetEnumerator()
				
			End Sub

			
			Overridable ReadOnly Property Current() As object _
				Implements IEnumerator.Current
			
				Get 
				
					Return baseEnumerator.Current
					
				End Get
				
			End Property
			
			
			Function MoveNext() As Boolean _
				 Implements IEnumerator.MoveNext
			
				Return baseEnumerator.MoveNext()
				
			End Function

			
			Sub Reset() _
				 Implements IEnumerator.Reset
			
				baseEnumerator.Reset()
			
			End Sub
			
		End Class
		
	End Class
	

	#End Region
	#Region "<xsl:value-of select="@name"/>"

	&lt;Serializable()&gt; _
	<xsl:choose>
		<xsl:when test="@inherit">
			<xsl:choose>
				<xsl:when test="@implement">Public Class <xsl:value-of select="@name"/> 
				Inherits <xsl:value-of select="@inherit"/> 
				Implements <xsl:value-of select="@implement"/>
					
				</xsl:when>
				<xsl:otherwise>Public Class <xsl:value-of select="@name"/> 
				Inherits <xsl:value-of select="@inherit"/> 
					
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="@implement">Public Class <xsl:value-of select="@name"/> 
				Implements IPersistable
				Implements <xsl:value-of select="@implement"/>
				</xsl:when>
				<xsl:otherwise>Public Class <xsl:value-of select="@name"/> 
				Implements IPersistable	
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>	
	</xsl:choose>
	
	
	
	
	<xsl:if test = "not(@inherit)">	
	
		Dim Protected _Entity As Uss.Entity
		
		&lt;NonSerialized()&gt; _
		Dim Protected _PersistenceManager As ObjectContext
		
		Property Entity() As Uss.Entity _
			Implements IPersistable.Entity 
		
			Get
			
				Return _Entity
				
			End Get
			
			Set
			
				_Entity = value
				
			End Set
			
		End Property
		
		Property  ObjectContext() As ObjectContext _
				Implements IPersistable.ObjectContext
		
			Get
			
				Return _PersistenceManager
				
			End Get
			
			Set
			
				_PersistenceManager = value
				
			End Set
		
		End Property	

		
		Property Id() As String _
			Implements IPersistable.Id
		
			Get
			
				Return _Entity.Id
				
			End Get
			
			Set
			
				_Entity.Id = value
				
			End Set
			
		End Property
		
		Protected Overrides Sub Finalize()
			_PersistenceManager.RemoveFromCache(Me)
		End Sub
		
	</xsl:if>
	
	<xsl:if test="not(@inherit)">
	<xsl:text>
		Sub TrackChildren() _
			 Implements IPersistable.TrackChildren
		
			If _PersistenceManager Is Nothing Then
			
				Return
				
			End If
			
	</xsl:text>
	</xsl:if>
	
	<xsl:if test="(@inherit)">
	<xsl:text>
		Shadows Sub TrackChildren()
		
			If _PersistenceManager Is Nothing Then
			
				Return
				
			End If
			
	</xsl:text>
	</xsl:if>
		
	<xsl:if test="not(@inherit)">
	
		<xsl:variable name="className" select="@name"/>
		<xsl:apply-templates select="//Relationship" mode="TrackChildren">
			<xsl:with-param name="className" select="$className"/>
		</xsl:apply-templates>
		End Sub
		
		<xsl:text>
		Sub DeleteChildren() _
			Implements IPersistable.DeleteChildren
		
		</xsl:text>
	</xsl:if> 
	<xsl:if test="(@inherit)">
		<xsl:variable name="className" select="@name"/>
		<xsl:apply-templates select="//Relationship" mode="TrackChildren">
			<xsl:with-param name="className" select="$className"/>
		</xsl:apply-templates>
		
		<xsl:variable name="className2" select="@inherit"/>
		<xsl:apply-templates select="//Relationship" mode="TrackChildren">
			<xsl:with-param name="className" select="$className2"/>
		</xsl:apply-templates> 
		End Sub
		
		<xsl:text>
		Shadows Sub DeleteChildren()
			
		</xsl:text>
	</xsl:if>
		
		

	
	
	<xsl:if test="not(@inherit)">
			<xsl:variable name="className" select="@name"/>
			<xsl:apply-templates select="//Relationship" mode="DeleteChildren">
				<xsl:with-param name="className" select="$className"/>
			</xsl:apply-templates>
		End Sub
	</xsl:if> 
	<xsl:if test="(@inherit)">
		<xsl:variable name="className" select="@name"/>
			<xsl:apply-templates select="//Relationship" mode="DeleteChildren">
				<xsl:with-param name="className" select="$className"/>
			</xsl:apply-templates>
			
			<xsl:variable name="className2" select="@inherit"/>
			<xsl:apply-templates select="//Relationship" mode="DeleteChildren">
				<xsl:with-param name="className" select="$className2"/>
			</xsl:apply-templates>
		End Sub
	</xsl:if>
			
<!--///////////////////// INTERFACE ////////////////-->

<apply-templates select="//Interface" mode="suite">
	<xsl:with-param name="implement" select="@implement"/>
	<xsl:with-param name="className" select="@name"/>
</apply-templates>
<!--//////////////////////////////////////////////////-->
		Public Sub New()
		
			MyBase.New
			Dim fullType As String 
			fullType= ObjectContext.ConvertNamespaceDomainToEuss(Me.GetType().FullName)
			Me._Entity = new Uss.Entity(fullType)
			Dim _Parents As ParentRelationships = new ParentRelationships(Me)
			
		End Sub
		

		Public Sub New(ByVal e As Uss.Entity)
			
			Me.New
			Me._Entity = e
		
		End Sub
		
		Private _Parents As ParentRelationships
	<xsl:if test="(@inherit)">
		Public Shadows ReadOnly Property Parents() As ParentRelationships
		
			Get 
			
				Return _Parents
				
			End Get
		
		End Property
		
		Public Shadows Class ParentRelationships
	</xsl:if>
	<xsl:if test="not(@inherit)">
		Public ReadOnly Property Parents() As ParentRelationships
		
			Get 
			
				Return _Parents
				
			End Get
		
		End Property
		
		Public Class ParentRelationships
	</xsl:if>
			Dim Private _Owner As IPersistable

			Public Sub New(o As IPersistable)
			
				_Owner = o
				
			End Sub
		
			<xsl:variable name="parent" select= "true()"/>
		
			<xsl:apply-templates select="." mode="relation">
				<xsl:with-param name="parent" select="$parent"/>
				<xsl:with-param name="namespace" select="$namespace"/>
			</xsl:apply-templates>
			
		End Class
			
		<xsl:apply-templates select="." mode="relation">
			<xsl:with-param name="parent" select= "false()"/>
			<xsl:with-param name="namespace" select="$namespace"/>
		</xsl:apply-templates>
		
		<xsl:apply-templates select="/" mode="enumeration">
			<xsl:with-param name="className" select="@name"/>
			<xsl:with-param name="namespace" select="$namespace"/>
		</xsl:apply-templates>
	End Class
	
	#End Region
</xsl:template>

		
<!--///////////////////// INTERFACE PROPERTIES ////////////////-->

<xsl:template match="//Interface" mode="suite">
<xsl:param name="implement"/>
	<xsl:if test = "@name = $implement">
		<xsl:apply-templates select="Property" mode="InterfaceCode">
			<xsl:with-param name="interfaceName" select="@name"/>
		</xsl:apply-templates>
	</xsl:if>
</xsl:template>


<xsl:template match="Property" mode="InterfaceCode">
	<xsl:param name="interfaceName"/>
								
		Public Property <xsl:value-of select="@name"/> As <xsl:value-of select="@type"/> _
			Implements <xsl:value-of select="$interfaceName"/>.<xsl:value-of select="@name"/>
		
			Get 
			
				Return CType(Me._Entity("<xsl:value-of select="@name"/>"),<xsl:value-of select="@type"/>)
			
			End Get
			
			Set 
			
				Me._Entity("<xsl:value-of select="@name"/>") = value
				
			End Set
			
		End Property
</xsl:template>


<!--/////////////// ENUMERATION ///////////////////////////-->
		
<xsl:template match="/" mode="enumeration">
	<xsl:param name="className"/>
	<xsl:apply-templates select="//Relationship" mode="enumeration">
		<xsl:with-param name ="className" select="$className"/>
	</xsl:apply-templates>

</xsl:template>


<xsl:template match="//Relationship" mode="enumeration">
<xsl:param name="className"/>
		<xsl:variable name="childname" select="Child/@name" />
		<xsl:variable name="parentname" select="Parent/@name" />
		<xsl:variable name="childrole" select="Child/@role" />
						
		
		<xsl:apply-templates select="//Enumeration" mode="enumeration">				
			<xsl:with-param name ="childname" select="$childname"/>
			<xsl:with-param name ="parentname" select="$parentname"/>
			<xsl:with-param name ="childrole" select="$childrole"/>
			<xsl:with-param name ="className" select="$className"/>
		</xsl:apply-templates>		
				
</xsl:template>

<xsl:template match="//Enumeration" mode="enumeration">
<xsl:param name="childname"/>
<xsl:param name="parentname"/>
<xsl:param name="childrole"/>
<xsl:param name="className"/>

		<xsl:if test="$childname = @name">
		
			<xsl:if test="$className = $parentname">
		#Region "enumeration"
								
		Public Property <xsl:value-of select="$childname"/>() As <xsl:value-of select="$childrole"/>
		
			Get 
			
				Return CType(Me._Entity("<xsl:value-of select="$childrole"/>"), <xsl:value-of select="$childname"/>)
				
			End Get
			
		
			Set 
			
				Me._Entity("<xsl:value-of select="$childrole"/>") = value
				
			End Set
			
		End Property
		
		#End Region									
			</xsl:if>
		</xsl:if>
</xsl:template>

<!--/////////////////TRACK AND DELETE CHILDREN////////////////////////-->	
	
<xsl:template match="//Relationship" mode="DeleteChildren">
	<xsl:param name="className"/>
	<xsl:if test="@type ='composition'" >
		<xsl:apply-templates select="." mode="CompoDelete">
			<xsl:with-param name="className" select="$className"/>
		</xsl:apply-templates>	
	</xsl:if>
</xsl:template>


<xsl:template match="//Relationship" mode="TrackChildren">
<xsl:param name="className"/>
	<xsl:if test = "($className = Parent/@name) and ((Child/@multiplicity = '*') or (Child/@multiplicity = '0..*'))">
			_PersistenceManager.TrackObject(_<xsl:value-of select="Child/@role"/>)</xsl:if>	

		
</xsl:template>


<!--/////////////////COMPOSITION DELETE////////////////////////-->	

<xsl:template match="Relationship" mode="CompoDelete">
	<xsl:param name="className"/>
	<xsl:param name="namespace"/>
	
		<xsl:variable name="childMultiplicity" select="Child/@multiplicity"/>
			<xsl:variable name="parentMultiplicity" select="Parent/@multiplicity"/>
			
				<xsl:choose>
					<xsl:when test="(($childMultiplicity = 1) or ($childMultiplicity ='0..1') or ($childMultiplicity ='1:1')) and (($parentMultiplicity = 1) or ($parentMultiplicity = '0..1') or ($parentMultiplicity = '1:1'))">
						
						<xsl:apply-templates select="." mode="OneToOneDelete">
							<xsl:with-param name="className" select="$className"/> 
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
						
					</xsl:when>
					<xsl:when test="(($childMultiplicity='*')or ($childMultiplicity ='0..*')) and (($parentMultiplicity = 1) or ($parentMultiplicity = '0..1') or ($parentMultiplicity = '1:1'))">
						
						<xsl:apply-templates select="." mode="OneToManyDelete">
							<xsl:with-param name="className" select="$className"/> 
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
					</xsl:when>
				</xsl:choose>
</xsl:template>	

<xsl:template match="Relationship" mode="OneToOneDelete">
			
	<xsl:param name="className"/>				

	<xsl:variable name="name" select="Child/@name" />	
	
	<xsl:if test="$name = $className">
			_PersistenceManager.Delete(<xsl:value-of select="Parent/@role"/>)
	</xsl:if>
</xsl:template>

<xsl:template match="Relationship" mode="OneToManyDelete">
			
	<xsl:param name="className"/>				

	<xsl:variable name="name" select="Parent/@name" />	
	
	<xsl:if test="$name = $className">
			_PersistenceManager.Delete(<xsl:value-of select="Child/@role"/>)	
	</xsl:if>
</xsl:template>


<!--/////////////// PROPRIETES ///////////////////////////-->

<xsl:template match="Property">
		Public Property <xsl:value-of select="@name"/> As <xsl:value-of select="@type"/>
		
			Get 
			 
				Return CType(Me._Entity("<xsl:value-of select="@name"/>"),<xsl:value-of select="@type"/>)
				
			End Get
			
		
			Set 
			
				Me._Entity("<xsl:value-of select="@name"/>") = value 
				
			End Set
			
		End Property
		<xsl:apply-templates/>	
	</xsl:template>

<!--/////////////// RELATIONS  ///////////////////////////-->

	<xsl:template match="Class" mode="relation">
	<xsl:param name="parent"/>
	<xsl:param name="namespace"/>
	
		#Region "relations"
		<xsl:variable name="className" select="@name"/>
				
				
			<xsl:apply-templates select="//Relationship" mode="relation">
				<xsl:with-param name="className" select="$className"/>
				<xsl:with-param name="parent" select="$parent"/>
				<xsl:with-param name="namespace" select="$namespace"/>
			</xsl:apply-templates>
				
		#End Region	
		
		<xsl:if test="$parent = false()">
		#Region "properties"
		
			<xsl:apply-templates select="Property"/>
			
		#End Region
		
		
			<xsl:apply-templates select="/" mode="enumeration"/>
		
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="Relationship" mode="relation">
	<xsl:param name="className"/>
	<xsl:param name="parent"/>
	<xsl:param name="namespace"/>
	
		<xsl:variable name="typeRelation" select="@type" />
			
			<xsl:choose>
				<xsl:when test="$typeRelation='composition'" >
					
					<xsl:apply-templates select="." mode="Composition">
						<xsl:with-param name="className" select="$className"/>
						<xsl:with-param name="parent" select="$parent"/>
						<xsl:with-param name="namespace" select="$namespace"/>
					</xsl:apply-templates>
							
				</xsl:when>
				<xsl:when test="$typeRelation= 'aggregation'" >
					<xsl:apply-templates select="." mode="Aggregation" >
						<xsl:with-param name="className" select="$className"/> 
						<xsl:with-param name="parent" select="$parent"/>
						<xsl:with-param name="namespace" select="$namespace"/>
					</xsl:apply-templates>
						
				</xsl:when>
				<xsl:otherwise>
					
				</xsl:otherwise>
			</xsl:choose>
	</xsl:template>
	
<!--/////////////// COMPOSITION ///////////////////////////-->		
		
		<xsl:template match="Relationship" mode="Composition">	
		<xsl:param name="className"/>
		<xsl:param name="parent"/>
		<xsl:param name="namespace"/>
			
			<xsl:variable name="childMultiplicity" select="Child/@multiplicity"/>
			<xsl:variable name="parentMultiplicity" select="Parent/@multiplicity"/>
			
				<xsl:choose>
					<xsl:when test="($childMultiplicity = 1) or ($childMultiplicity ='0..1') or ($childMultiplicity ='1:1')">
						
						<xsl:apply-templates select="." mode="CRelationOneToOne">
							<xsl:with-param name="className" select="$className"/>
							<xsl:with-param name="parent" select="$parent"/>
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
						
					</xsl:when>
					<xsl:when test="($childMultiplicity='*')or ($childMultiplicity ='0..*')">
						
						<xsl:apply-templates select="." mode="CRelationOneToMany">
							<xsl:with-param name="className" select="$className"/>
							<xsl:with-param name="parent" select="$parent"/>
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
					</xsl:when>
				</xsl:choose>
					
		<xsl:apply-templates/>	
	</xsl:template>	

<!--/////////////// COMPOSITION ONE TO ONE ///////////////////////////-->	
	
	<xsl:template match="Relationship" mode="CRelationOneToOne">	
	<xsl:param name="className"/>
	<xsl:param name="parent"/>
	<xsl:param name="namespace"/>

	<xsl:variable name="parentName" select="Parent/@name"/>	
	<xsl:variable name="childName" select="Child/@name"/>
	<xsl:variable name="childRole" select="Child/@role"/>
	<xsl:variable name="parentRole" select="Parent/@role"/>
		
	
	<xsl:if test="($parentName = $className) and (//Enumeration/@name != childName) and ($parent = false())">
						
		'///Composition OneToOne/////	
				
			Dim Protected _<xsl:value-of select="$childRole"/> As <xsl:value-of select="$childName"/>
		
			Public Property <xsl:value-of select="$childName"/>() <![CDATA[ ]]><xsl:value-of select="$childName"/>
			
				Get 
				
					If _<xsl:value-of select="$childRole"/> Is Nothing Then
					
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>(_Entity.GetEntity("<xsl:value-of select="$childName"/>"))
						
					
					End If
					Return _<xsl:value-of select="$childRole"/>;
				
				End Get
				
				Set
				
					If value Is Nothing Then
					
						_Entity.RemoveReference("<xsl:value-of select="$childName"/>")
					
					Else
					
						If _Entity.GetEntity("<xsl:value-of select="$childName"/>") Is Nothing Then
							_Entity.RemoveReference("<xsl:value-of select="$childName"/>")
						End If

						_Entity.AddValue("<xsl:value-of select="$childName"/>", ((IPersistable)value).Entity)
					
					End If
					_<xsl:value-of select="$childRole"/> = value
					
				End Set
			End Property
	</xsl:if>
	
	<xsl:if test = "$parent = true()">
		<xsl:if test="($childName = $className)">
	
		Public Function Get<xsl:value-of select="$parentRole"/>() AS <xsl:value-of select="$parentName"/> 
		
			Dim persistables As IPersistable()  = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			
			If (persistables.Length>0) Then
			
			
					Return CType(persistables(0),<xsl:value-of select="$parentName"/>)
			Else
			
					Return Nothing 
			
			End If
			
		End Function
	
		</xsl:if>
	</xsl:if>
	<xsl:apply-templates/>	
	</xsl:template>	
	
	<!--/////////////// COMPOSITION ONE TO MANY ///////////////////////////-->	
	
<xsl:template match="Relationship" mode="CRelationOneToMany">	
	<xsl:param name="className"/>
	<xsl:param name="parent"/>
	<xsl:param name="namespace"/>

	<xsl:variable name="parentName" select="Parent/@name"/>	
	<xsl:variable name="childName" select="Child/@name"/>
	<xsl:variable name="childRole" select="Child/@role"/>
	<xsl:variable name="parentRole" select="Parent/@role"/>
		
	
	<xsl:if test="($parentName = $className) and ($parent = false())">
						
		'///Composition OneToMany/////	

		Dim Protected _<xsl:value-of select="$childRole"/> As <xsl:value-of select="$childName"/>Collection
	
		Public ReadOnly Property <xsl:value-of select="$childRole"/>() As <xsl:value-of select="$childName"/>Collection 
		
			Get
			
				If _<xsl:value-of select="$childRole"/> Is Nothing Then
					Dim data() As Object = {}
					
					If _PersistenceManager Is Nothing Then '// il s'agit alors d'une collection à part
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>Collection(_Entity, "<xsl:value-of select="$childRole"/>", data) '//object[0] initialisé avec rien dedans
					Else
					
						Dim refs() As object = _PersistenceManager.LoadReference(_Entity, "<xsl:value-of select="$childRole"/>")
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>Collection(_Entity, "<xsl:value-of select="$childRole"/>", refs) 
					
					End If
				End If
				
				Return _<xsl:value-of select="$childRole"/>
				
			End Get
			
		End Property

	</xsl:if>
	
	<xsl:if test = "$parent = true()">
		<xsl:if test="($childName = $className)">
	
		Public Function Get<xsl:value-of select="$parentRole"/>() AS <xsl:value-of select="$parentName"/> 
		
			Dim persistables As IPersistable()  = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			
			If (persistables.Length>0) Then
			
			
					Return CType(persistables(0),<xsl:value-of select="$parentName"/>)
			Else
			
					Return Nothing 
			
			End If
			
		End Function
	
		</xsl:if>
	</xsl:if>

	<xsl:apply-templates/>			
		
	</xsl:template>
	
	
<!--/////////////// AGGREGATION///////////////////////////-->	
		<xsl:template match="Relationship" mode="Aggregation">	
			<xsl:param name="className"/>
			<xsl:param name="parent"/>
			<xsl:param name="namespace"/>
			
			
			<xsl:variable name="childMultiplicity" select="Child/@multiplicity"/>
			<xsl:variable name="parentMultiplicity" select="Parent/@multiplicity"/>
			
				<xsl:choose>
					<xsl:when test="($childMultiplicity = 1) or ($childMultiplicity ='0..1') or ($childMultiplicity ='1:1')">
						
						<xsl:apply-templates select="." mode="ARelationOneToOne">
							<xsl:with-param name="className" select="$className"/> 
							<xsl:with-param name="parent" select="$parent"/>
							<xsl:with-param name="parentMultiplicity" select="$parentMultiplicity"/>
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
						
					</xsl:when>
				
					<xsl:when test="($childMultiplicity='*')or ($childMultiplicity ='0..*')">
						
						<xsl:apply-templates select="." mode="ARelationOneToMany">
							<xsl:with-param name="className" select="$className"/> 
							<xsl:with-param name="parent" select="$parent"/>
							<xsl:with-param name="parentMultiplicity" select="$parentMultiplicity"/>
							<xsl:with-param name="namespace" select="$namespace"/>
						</xsl:apply-templates>
						
					</xsl:when>
				
					<xsl:otherwise>
					
					</xsl:otherwise>
					
				</xsl:choose>
					
		<xsl:apply-templates/>	
	</xsl:template>	

	
	
<!--/////////////// AGGREGATION ONE TO ONE ///////////////////////////-->	
	
	<xsl:template match="Relationship" mode="ARelationOneToOne">	
	<xsl:param name="parent"/>
	<xsl:param name="className"/>
	<xsl:param name="parentMultiplicity"/>	
	<xsl:param name="namespace"/>	

	<xsl:variable name="parentName" select="Parent/@name" />
	<xsl:variable name="parentRole" select="Parent/@role" />
	<xsl:variable name="childName" select="Child/@name" />	
	<xsl:variable name="childRole" select="Child/@role" />		
		
	
	<xsl:if test="($parentName = $className) and ($parent = false())">
						
		'///Aggregation OneToOne/////	
				
			Dim Protected _<xsl:value-of select="$childRole"/> As  <xsl:value-of select="$childName"/>
		
			Public Property <xsl:value-of select="$childName"/>() As <xsl:value-of select="$childName"/> 
			
				Get 
				
					If _<xsl:value-of select="$childRole"/> Is Nothing Then
					
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>(_Entity.GetEntity("<xsl:value-of select="$childName"/>")) '//.GetEntitySet("Parents") pour les colections		
					End If
					Return _<xsl:value-of select="$childRole"/>;
				
				End Get
				
				Set
				
					If value Is Nothing Then
					
						_Entity.RemoveReference("<xsl:value-of select="$childName"/>")
					
					Else
					
						If _Entity.GetEntity("<xsl:value-of select="$childName"/>") Is Nothing Then
							_Entity.RemoveReference("<xsl:value-of select="$childName"/>")
						End If
						_Entity.AddValue("<xsl:value-of select="$childName"/>", ((IPersistable)value).Entity)
						
					End If
					_<xsl:value-of select="$childRole"/> = value
				
				End Set
				
			End Property

	</xsl:if>
	
	
	<xsl:if test = "$parent = true()">
		<xsl:if test="(Child/@name = $className) and (($parentMultiplicity = '*') or ($parentMultiplicity = '0..*'))">
						
		Public Function Get<xsl:value-of select="$parentRole"/>() As <xsl:value-of select="$parentName"/>()
		
			Dim persistables As IPersistable() = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			''Dim result As <xsl:value-of select="$parentName"/>()  = new <xsl:value-of select="$parentName"/>(persistables.Length)
			Dim result(persistables.Length) As <xsl:value-of select="$parentName"/>

			persistables.CopyTo(result, 0)

			Return result
			
		End Function
	
		</xsl:if>
	
		<xsl:if test="($childName = $className) and (($parentMultiplicity = 1) or ($parentMultiplicity = '0..1') or ($parentMultiplicity = '1:1'))">
	
		Public Function Get<xsl:value-of select="$parentRole"/>() As <xsl:value-of select="$parentName"/> 
		
			Dim persistables As IPersistable()  = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			
			If (persistables.Length>0) Then
			
			
					Return CType(persistables(0),<xsl:value-of select="$parentName"/>)
			Else
			
					Return Nothing 
			
			End If
			
		End Function
	
		</xsl:if>
	</xsl:if>
	
	<xsl:apply-templates/>			
		
	</xsl:template>
	
	
<!--/////////////// AGGREGATION ONE TO MANY ///////////////////////////-->	
	
	<xsl:template match="Relationship" mode="ARelationOneToMany">	
	<xsl:param name="parent"/>	
	<xsl:param name="className"/>
	<xsl:param name="parentMultiplicity"/>	
	<xsl:param name="namespace"/>		

	<xsl:variable name="parentName" select="Parent/@name" />
	<xsl:variable name="parentRole" select="Parent/@role" />
	<xsl:variable name="childName" select="Child/@name" />	
	<xsl:variable name="childRole" select="Child/@role" />	
		
	
	<xsl:if test="($parentName = $className) and ($parent = false())">
						
		'///Aggregation OneToMany/////	

		Dim Protected _<xsl:value-of select="$childRole"/> As <xsl:value-of select="$childName"/>Collection
		
		Public ReadOnly Property <xsl:value-of select="$childRole"/>() As <xsl:value-of select="$childName"/>Collection 
		
			Get
			
				If _<xsl:value-of select="$childRole"/> Is Nothing Then
					Dim data() As Object = {}
					
					If _PersistenceManager Is Nothing Then '// il s'agit alors d'une collection à part
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>Collection(_Entity, "<xsl:value-of select="$childRole"/>",data) '//object[0] initialisé avec rien dedans
					
					Else
					
						Dim refs() As object = _PersistenceManager.LoadReference(_Entity, "<xsl:value-of select="$childRole"/>")
						_<xsl:value-of select="$childRole"/> = new <xsl:value-of select="$childName"/>Collection(_Entity, "<xsl:value-of select="$childRole"/>", refs)
					
					End If
					
				End If
				Return _<xsl:value-of select="$childRole"/>
				
			End Get
				
		End Property	
			
	</xsl:if>
	
	
	<xsl:if test = "$parent = true()">
		<xsl:if test="(Child/@name = $className) and (($parentMultiplicity = '*') or ($parentMultiplicity = '0..*'))">
						
		
		Public Function Get<xsl:value-of select="$parentRole"/>() As <xsl:value-of select="$parentName"/>()
		
			Dim persistables As IPersistable() = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			''Dim result As <xsl:value-of select="$parentName"/>()  = new <xsl:value-of select="$parentName"/>(persistables.Length)
			Dim result(persistables.Length) As <xsl:value-of select="$parentName"/>
			
			persistables.CopyTo(result, 0)

			Return result
			
		End Function
	
		</xsl:if>
	
		<xsl:if test="($childName = $className) and (($parentMultiplicity = 1) or ($parentMultiplicity = '0..1') or ($parentMultiplicity = '1:1'))">
	
		Public Function Get<xsl:value-of select="$parentRole"/>() As <xsl:value-of select="$parentName"/> 
		
			Dim persistables As IPersistable()  = _Owner.ObjectContext.Load(String.Format("<xsl:value-of select="$namespace"/>:<xsl:value-of select="$parentName"/>[<xsl:value-of select="$childRole"/>.Id = '{0}']", _Owner.Id))
			
			If (persistables.Length>0) Then
			
			
					Return CType(persistables(0),<xsl:value-of select="$parentName"/>)
			Else
			
					Return Nothing 
			
			End If
			
			
			
		End Function
	
		</xsl:if>
	</xsl:if>
	
	<xsl:apply-templates/>			
		
	</xsl:template>
	

</stylesheet>

  